package moriarty.gwt.shared;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * An Objectify class for using persistent storage on the google app engine.
 * 1. Must have an @Id of type Long, long, or String (recommend Long)
 * 2. Must register class (this is done in the ObjectifyRegistrar class, which extends ContextListener)
 * 3. Add the registrar to the web.xml as a <listener>
 * @author cmoriarty
 *
 */
public class Group extends DataStoreObject implements Serializable{

	//For serialization through RPC
	private static final long serialVersionUID = 3641626947563608322L;
	
	public String groupName;
	String creator;
	
	public List<String> members = new ArrayList<String>();
	
	public String groupMessage;
	public Date established;

	//Objectify needs a blank constructor
	public Group(){}

	public Group(String groupName, String groupMessage, Date established, String creator) {
		this.groupName = groupName;
		this.groupMessage = groupMessage;
		this.established = established;
		this.creator = creator;
		this.members.add(creator);
	}
	
	//Cross Site Scripting Defense
	public void escapeGroup(){
		this.groupName = Utils.escapeHtml(groupName);
		this.groupMessage = Utils.escapeHtml(groupMessage);
	}
}
